#!/usr/bin/perl -w
use strict;
my $fh1;
my $fh2;
my $readname;
my $out;

#open $fh1,"/home/aaithal/indel/manual/out.r1.fq" or die "could not open $_";
open $fh1,$ARGV[0] or die "could not open $_";
open $fh2,$ARGV[1] or die "could not open $_";

#open $fh2,"/home/aaithal/indel/manual/out.r2.fq" or die "could not open $_";
#open $out,">merge.fq";
my @f1_cont = <$fh1>;
my @f2_cont = <$fh2>;

my $len = scalar (@f1_cont);
my $counter = 0;
#my $label = $counter;

#open ($out,$outfn.$label.".fq");
open ($out,">".$ARGV[2]) or die "could not open $_";
#print "len: $len\n";
for(my $ix = 0; $ix < $len;){
#	if($counter <100000){
		my $temp;
		my $read_name = $f1_cont[$ix++];
		chomp($read_name);
		$read_name =~ s/(.*)(\/[0-9])/$1/;
		$temp = $read_name."\t";

	#	$ix++;
		my $seq_data = $f1_cont[$ix++];
		chomp($seq_data);
		$temp .= $seq_data."\t";
	
	
		$ix++;
		my $q_data = $f1_cont[$ix];
		chomp($q_data);
		$temp .= $q_data."\t";
	
		$ix -= 2;
		$seq_data = $f2_cont[$ix++];
		chomp($seq_data);
		$temp .= $seq_data."\t";
		$ix++;

		$q_data = $f2_cont[$ix++];
		chomp($q_data);
		$temp .= $q_data."\n";

		print $out $temp;
=pod
		$counter++;
	}else{
		$counter = 0;
		$label++;
		close $out;
		open ($out,$outfn.$label.".fq") or die "";
		print "here $label\n";
	}
=cut
}
#while(1){
#	$readname = <$fh1>;
#	chomp($readname);
#	<$fh2>;
#	$readname =~ s/(.*)(\/[0-9])/$1/; 
#	last unless defined $readname;
#	print $out $readname;
#}

close $out;
close $fh2;
close $fh1;

